package zyh.struts2.action2;

import com.opensymphony.xwork2.Action;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

public class LoginAction implements Action {
    private String username;
    private String password;
    private InputStream inputStream;
    public InputStream getResult()
    {
        return inputStream;
    }
    @Override
    public String execute() throws Exception {
        inputStream =username.equals("admin")&&password.equals("123")
                ? new ByteArrayInputStream("<h1>恭喜登录成功</h1>".getBytes("UTF-8"))
                :new ByteArrayInputStream("<h1>请重新登录</h1>".getBytes("UTF-8"));
        return SUCCESS;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) { this.password = password; }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) { this.inputStream = inputStream; }
    public LoginAction(){
        System.out.println("被实例化");
    }
}
